/*
 * @LastEditTime: 2023-03-30 23:15:58
 * @Method: 
 * @Description: 
 */
package CodeTop;

public class Solution206 {
    // public ListNode reverseList(ListNode head) {
    //     ListNode pre = null;
    //     ListNode cur = head;
    //     while (cur != null) {
    //         ListNode t = cur.next;
    //         cur.next = pre;
    //         pre = cur;
    //         cur = t;
    //     }
    //     return pre;
    // }

    public ListNode[] reverse (ListNode head) {
        if (head.next == null) {
            return new ListNode[]{head, head};
        }
        ListNode[] t = reverse(head.next);
        t[0].next = head;
        return new ListNode[]{head, t[1]};
    }

    public ListNode reverseList (ListNode head) {
        if (head == null) {
            return head;
        }
        ListNode[] l = reverse(head);
        l[0].next = null;
        return l[1];
    }
}
